<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>块级元素水平垂直居中</title>
    <style type="text/css">
        .box{
            width: 200px;
            height: 200px;
            background-color: red;
            position: relative;
        }
        .child{
            width: 50px;
            height: 50px;
            background-color: green;
            /* 水平居中 */
            /* margin: 0 auto; */
            position: absolute;
            /* margin: 0 auto; */
            left: 0;
            right: 0;
            margin: auto auto;
            top: 0;
            bottom: 0;
        }
    </style>
</head>
<body>
    <!-- 
        通过定位
    -->
    <div class="box">
        <div class="child"></div>
    </div>
</body>
</html>